/**
 * form表单
 */
seajs.use(["zui/form"],function(Form){
	var form1 = 
			new Form({srcNode:"#CM_Form",validType:"custom",validateFunc:function(ev){
				var field=ev.field;
				var msg=ev.validateMsg;
				if(msg==""){

				}else{
				  	App.showToast(msg);
			  	}
		  	}});
	$(".zaw-btn").on("click",function(){
		if( $("#changeId").val() == 1 ){	//开始修改
			$("#changeAccount").show();
			$("#changeId").val("0");
			cerCodeCheck("#idCard");
			phoneNumCheck("#mobile");
			$(this).html("确定");
		}else{	//修改完成
			if(form1.valid()){
				$("#changeAccount").hide();
				$("#changeId").val("1");
				//验证通过，提交
				$("#CM_Form").submit();
				$(this).html("修改个人信息");
			}
		}
	});
	//选择证件类型
	$(".certype-select").on("change",function(){
		var idType = $(this).val();
		if( idType == "1" || idType == "I" ){		//身份证=I
			$(this).parents(".form-box").find("#idCard").attr("data-rules","{required:true,isIdCard:'请输入正确证件号!'}");
			$(this).parents(".form-box").find("#idCard").attr("data-messages","{required:'请输入您的证件号码',isIdCard:'请输入正确证件号!'}");
			$(this).parents(".form-box").find(".form-date").attr("readonly","readonly");
		}else{
			$(this).parents(".form-box").find("#idCard").attr("data-rules","{required:true}");
			$(this).parents(".form-box").find("#idCard").attr("data-messages","{required:'请输入您的证件号码'}");
			$(this).parents(".form-box").find(".form-date").removeAttr("readonly");
		}
	});
});

//检测身份证手机号
function cerCodeCheck(e){
	var code = $(e).val();
	if( code ){
		$(e).attr("readonly","readonly");
	}else{
		$(e).removeAttr("readonly");
	}
}
function phoneNumCheck(e){
	var code = $(e).val();
	if( code ){
		$(e).attr("readonly","readonly");
	}else{
		$(e).removeAttr("readonly");
	}
}